package cn.com.w.thread.demo.sync;

import org.openjdk.jol.info.ClassLayout;

/**
 * synchronized字节码层级
 *
 * 编译成字节码文件内容:
 *  0 new #2 <java/lang/Object>
 *  3 dup
 *  4 invokespecial #1 <java/lang/Object.<init> : ()V>
 *  7 astore_1
 *  8 aload_1
 *  9 dup
 * 10 astore_2
 * 11 monitorenter
 * 12 getstatic #3 <java/lang/System.out : Ljava/io/PrintStream;>
 * 15 ldc #4 <ok>
 * 17 invokevirtual #5 <java/io/PrintStream.println : (Ljava/lang/String;)V>
 * 20 aload_2
 * 21 monitorexit
 * 22 goto 30 (+8)
 * 25 astore_3
 * 26 aload_2
 * 27 monitorexit
 * 28 aload_3
 * 29 athrow
 * 30 return
 */
public class SyncClassCode {
    public static void main(String[] args) {
        Object obj = new Object();
        synchronized (obj){
            System.out.println("ok");
        }
    }
}
